<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>预约信息 - 猫咖管理系统</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
    <style>
        /* 全局样式 */
        :root {
            --primary-color: #D85D5D;
            --secondary-color: #9B7E46;
            --accent-color: #FFA384;
            --light-color: #F8F3EA;
            --dark-color: #333333;
            --success-color: #4CAF50;
            --error-color: #FF5252;
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f9f9f9;
            color: var(--dark-color);
            line-height: 1.6;
        }

        .container {
            width: 100%;
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }

        /* 顶部导航栏样式 */
        header {
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .header-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 0;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .logo-icon {
            width: 40px;
            height: 40px;
            background-color: var(--primary-color);
            border-radius: 50%;
            position: relative;
        }

        .logo-icon::after {
            content: '';
            position: absolute;
            top: -4px;
            left: -4px;
            width: 48px;
            height: 48px;
            border-radius: 50%;
            border: 1px solid rgba(216, 93, 93, 0.2);
        }

        .logo h1 {
            font-size: 24px;
            color: var(--primary-color);
        }

        nav ul {
            display: flex;
            list-style: none;
            gap: 25px;
        }

        nav a {
            text-decoration: none;
            color: var(--dark-color);
            font-weight: 500;
            padding: 8px 12px;
            border-radius: 4px;
            transition: var(--transition);
            position: relative;
        }

        nav a:hover,
        nav a.active {
            color: var(--primary-color);
        }

        nav a::after {
            content: '';
            position: absolute;
            bottom: -5px;
            left: 0;
            width: 0;
            height: 2px;
            background-color: var(--primary-color);
            transition: var(--transition);
        }

        nav a:hover::after,
        nav a.active::after {
            width: 100%;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .user-info span {
            font-weight: 500;
        }

        .btn {
            padding: 8px 16px;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            font-weight: 500;
            transition: var(--transition);
        }

        .btn-primary {
            background-color: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background-color: #c74d4d;
        }

        .btn-outline {
            background-color: transparent;
            border: 1px solid var(--primary-color);
            color: var(--primary-color);
        }

        .btn-outline:hover {
            background-color: var(--primary-color);
            color: white;
        }

        .btn-danger {
            background-color: #e74c3c;
            color: white;
        }

        .btn-danger:hover {
            background-color: #c0392b;
        }

        /* 主要内容区域 */
        .main-content {
            padding: 40px 0 60px;
        }

        .section-title {
            text-align: center;
            margin-bottom: 40px;
            position: relative;
        }

        .section-title h2 {
            font-size: 32px;
            color: var(--primary-color);
            display: inline-block;
            margin-bottom: 15px;
        }

        .section-title::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 3px;
            background-color: var(--secondary-color);
        }

        /* 预约信息卡片 */
        .bookings-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
            gap: 30px;
        }

        .booking-card {
            background-color: white;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
            transition: var(--transition);
            display: flex;
            flex-direction: column;
        }

        .booking-header {
            background-color: var(--primary-color);
            color: white;
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .booking-id {
            font-weight: bold;
            font-size: 18px;
        }

        .booking-status {
            background-color: white;
            color: var(--primary-color);
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 14px;
            font-weight: 600;
        }

        .booking-status.completed {
            background-color: var(--success-color);
            color: white;
        }

        .booking-body {
            padding: 20px;
            flex-grow: 1;
        }

        .booking-info {
            margin-bottom: 15px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .info-row {
            display: flex;
            margin-bottom: 10px;
        }

        .info-label {
            width: 100px;
            color: #777;
            font-weight: 500;
        }

        .info-value {
            flex: 1;
            font-weight: 500;
        }

        .booking-footer {
            padding: 15px 20px;
            background-color: #f9f9f9;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .booking-time {
            color: #666;
            font-size: 14px;
        }

        .booking-actions {
            display: flex;
            gap: 10px;
        }

        /* 空状态 */
        .empty-state {
            text-align: center;
            padding: 50px 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
        }

        .empty-icon {
            font-size: 64px;
            color: #ddd;
            margin-bottom: 20px;
        }

        .empty-state h3 {
            color: #777;
            margin-bottom: 15px;
        }

        /* 加载动画 */
        .loader {
            text-align: center;
            padding: 40px;
            display: none;
        }

        .loader .spinner {
            border: 4px solid rgba(0, 0, 0, 0.1);
            border-radius: 50%;
            border-top: 4px solid var(--primary-color);
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 通知消息 */
        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 15px 25px;
            border-radius: 4px;
            color: white;
            font-weight: 500;
            z-index: 3000;
            opacity: 0;
            transform: translateX(100%);
            transition: all 0.3s ease;
        }

        .notification.success {
            background-color: var(--success-color);
            opacity: 1;
            transform: translateX(0);
        }

        .notification.error {
            background-color: var(--error-color);
            opacity: 1;
            transform: translateX(0);
        }

        /* 页脚样式 */
        footer {
            background-color: var(--dark-color);
            color: white;
            padding: 40px 0 20px;
        }

        .footer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 30px;
            margin-bottom: 30px;
        }

        .footer-column h3 {
            font-size: 20px;
            margin-bottom: 20px;
            position: relative;
            padding-bottom: 10px;
        }

        .footer-column h3::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 50px;
            height: 2px;
            background-color: var(--primary-color);
        }

        .footer-links {
            list-style: none;
        }

        .footer-links li {
            margin-bottom: 10px;
        }

        .footer-links a {
            color: #bbb;
            text-decoration: none;
            transition: var(--transition);
        }

        .footer-links a:hover {
            color: white;
            padding-left: 5px;
        }

        .contact-info {
            color: #bbb;
        }

        .contact-info p {
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .copyright {
            text-align: center;
            padding-top: 20px;
            border-top: 1px solid #444;
            color: #bbb;
            font-size: 14px;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .header-container {
                flex-direction: column;
                gap: 15px;
            }

            nav ul {
                flex-wrap: wrap;
                justify-content: center;
            }

            .bookings-container {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>

<!-- 顶部导航栏 -->
<header>
    <div class="container header-container">
        <div class="logo">
            <div class="logo-icon"></div>
            <h1>猫咖管理系统</h1>
        </div>

        <nav>
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="cat.html">猫咪预约</a></li>
                <li><a href="cafe.html">咖啡购买</a></li>
                <li><a href="center.html">个人中心</a></li>
                <li><a href="message.html">留言板</a></li>
<!--                <li><a href="shoppingcart.html">购物车</a></li>-->
                <li><a href="orders.html">订单信息</a></li>
                <li><a href="booking.html" class="active">预约信息</a></li>
            </ul>
        </nav>

        <!-- 用户信息 -->
        <div class="user-info">
            <span id="user-display">未登录</span>
            <button class="btn btn-primary" id="logout-btn">退出</button>
        </div>
    </div>
</header>

<!-- 主要内容区域 -->
<section class="main-content">
    <div class="container">
        <div class="section-title">
            <h2>我的预约信息</h2>
            <p>查看和管理您的猫咪预约记录</p>
        </div>

        <div class="loader" id="loader">
            <div class="spinner"></div>
            <p>正在加载预约信息...</p>
        </div>

        <div class="bookings-container" id="bookings-container">
            <!-- 预约卡片将通过JS动态生成 -->
        </div>
    </div>
</section>

<!-- 页脚 -->
<footer>
    <div class="container">
        <div class="footer-content">
            <div class="footer-column">
                <h3>关于我们</h3>
                <p>猫咖管理系统致力于为猫咪咖啡馆提供专业的管理解决方案，帮助店主高效管理猫咪、咖啡和顾客信息。</p>
            </div>

            <div class="footer-column">
                <h3>快速链接</h3>
                <ul class="footer-links">
                    <li><a href="index.html">首页</a></li>
                    <li><a href="cat.html">猫咪信息</a></li>
                    <li><a href="cafe.html">咖啡菜单</a></li>
                    <li><a href="">在线预订</a></li>
                    <li><a href="center.html">个人中心</a></li>
                </ul>
            </div>

            <div class="footer-column">
                <h3>联系方式</h3>
                <div class="contact-info">
                    <p><i class="fas fa-map-marker-alt"></i> 地址：广东科技学院</p>
                    <p><i class="fas fa-phone"></i> 电话：666666</p>
                    <p><i class="fas fa-envelope"></i> 邮箱：666666.com</p>
                    <p><i class="fas fa-clock"></i> 营业时间：10:00-18:00</p>
                </div>
            </div>
        </div>

        <div class="copyright">
            <p>© 2025 猫咖管理系统 版权所有 | 设计开发：会非的杨</p>
        </div>
    </div>
</footer>

<!-- 通知消息 -->
<div class="notification" id="notification"></div>

<script>
    // API端点配置
    const API_BASE_URL = 'http://localhost:8080/catcafe';
    const BOOKINGS_ENDPOINT = `${API_BASE_URL}/bookings/query`;

    document.addEventListener('DOMContentLoaded', function () {
        const bookingsContainer = document.getElementById('bookings-container');
        const loader = document.getElementById('loader');
        const notification = document.getElementById('notification');

        // 从localStorage获取用户信息
        const username = localStorage.getItem('username');
        const role = localStorage.getItem('role');

        // 获取显示用户信息的元素
        const userDisplay = document.getElementById('user-display');

        // 如果有用户信息，显示在导航栏
        if (username) {
            // 根据角色显示不同的文本
            const roleText = role === 'admin' ? '管理员' : '普通用户';
            userDisplay.textContent = `${roleText}：${username}`;

            // 添加角色图标（可选）
            userDisplay.innerHTML = `            <i class="fas fa-user-circle"></i>
            <span class="username-text">${username}</span>
            <span class="role-badge">${roleText}</span>
        `;
        } else {
            userDisplay.textContent = "未登录";
        }

        // 退出按钮功能
        const logoutBtn = document.getElementById('logout-btn');
        logoutBtn.addEventListener('click', function () {
            // 清除存储的用户信息
            localStorage.removeItem('username');
            localStorage.removeItem('role');

            // 提示用户并跳转到登录页
            alert('您已成功退出');
            window.location.href = 'login.html'; // 替换为你的登录页面路径
        });

        function showLoader() {
            loader.style.display = 'block';
            bookingsContainer.innerHTML = '';
        }

        function hideLoader() {
            loader.style.display = 'none';
        }

        function showNotification(message, isSuccess = true) {
            notification.textContent = message;
            notification.className = `notification ${isSuccess ? 'success' : 'error'}`;
            setTimeout(() => {
                notification.style.opacity = '0';
                notification.style.transform = 'translateX(100%)';
            }, 3000);
        }

        function fetchBookings() {
            showLoader();
            fetch(BOOKINGS_ENDPOINT)
                .then(response => {
                    if (!response.ok) throw new Error('网络响应异常');
                    return response.json();
                })
                .then(data => {
                    renderBookings(data.data);
                    hideLoader();
                })
                .catch(error => {
                    console.error('获取预约信息失败:', error);
                    hideLoader();
                    showEmptyState();
                });
        }

        function deleteBooking(bookingId) {
            if (!confirm('确定要删除此预约吗？此操作不可撤销。')) return;

            fetch(`http://localhost:8080/catcafe/delete/${bookingId}`, { method: 'DELETE' })
                .then(response => {
                    if (!response.ok) throw new Error('删除失败');
                    return response.json();
                })
                .then(() => {
                    showNotification('预约删除成功', true);
                    fetchBookings();
                })
                .catch(error => {
                    console.error('删除预约失败:', error);
                    showNotification('删除预约失败，请重试', false);
                });
        }

        function renderBookings(bookings) {
            bookingsContainer.innerHTML = '';

            if (!bookings || bookings.length === 0) {
                showEmptyState();
                return;
            }

            bookings.forEach(booking => {
                const bookingCard = document.createElement('div');
                bookingCard.className = 'booking-card';

                const bookingDate = new Date(booking.bookingDate);
                const formattedDate = bookingDate.toLocaleDateString('zh-CN', {
                    year: 'numeric',
                    month: 'long',
                    day: 'numeric'
                });

                const formattedTime = booking.timeSlot || '未指定时间';

                bookingCard.innerHTML = `
                    <div class="booking-header">
                        <div class="booking-id">预约号: #${booking.id}</div>

                    </div>
                    <div class="booking-body">
                        <div class="booking-info">
                            <div class="info-row">
                                <div class="info-label">猫咪:</div>
                                <div class="info-value">${booking.catName} </div>
                            </div>
                            <div class="info-row">
                                <div class="info-label">预约日期:</div>
                                <div class="info-value">${booking.bookingDate}</div>
                            </div>
                            <!--<div class="info-row">
                                <div class="info-label">时间段:</div>
                                <div class="info-value">${formattedTime}</div>
                            </div>-->
                            <div class="info-row">
                                <div class="info-label">用户昵称:</div>
                                <div class="info-value">${booking.userName}</div>
                            </div>
                        </div>
                        <div class="booking-remark">
                            <div class="info-label">备注信息:</div>
                            <div class="info-value">${booking.note || '无备注'}</div>
                        </div>
                    </div>
                    <div class="booking-footer">
                        <div class="booking-time">
                            下单时间: ${new Date(booking.orderDate).toLocaleString('zh-CN')}
                        </div>
                        <div class="booking-actions">
                            <button class="btn btn-danger delete-btn" data-id="${booking.id}">
                                <i class="fas fa-trash"></i> 删除
                            </button>
                        </div>
                    </div>
                `;

                bookingsContainer.appendChild(bookingCard);
            });

            document.querySelectorAll('.delete-btn').forEach(btn => {
                btn.addEventListener('click', function () {
                    const bookingId = this.getAttribute('data-id');
                    deleteBooking(bookingId);
                });
            });
        }

        function showEmptyState() {
            bookingsContainer.innerHTML = `
                <div class="empty-state">
                    <div class="empty-icon"><i class="fas fa-calendar-times"></i></div>
                    <h3>暂无预约信息</h3>
                    <p>您还没有任何猫咪预约记录，快去预约可爱的猫咪吧！</p>
                    <button class="btn btn-primary" style="margin-top: 20px;" onclick="location.href='cat.html'">
                        去预约猫咪
                    </button>
                </div>
            `;
        }

        fetchBookings();
    });
</script>

</body>
</html>
